#!/bin/bash

target_path="/apps/cadence/icadv20.10.000/doc"
 
if ! command -v pdfinfo &> /dev/null; then
    exit 1 
fi 
 
find "$target_path" -type f -iname "*.pdf" -print0 | while IFS= read -r -d $'\0' pdf_file; do
    title=$(pdfinfo "$pdf_file" | grep -m1 '^Title:' | sed 's/Title:[[:space:]]*//')
    
    if [ -z "$title" ]; then
        title=$(basename "$pdf_file" .pdf)
    fi 
    
    #final_title=$(echo "$title" | iconv -f UTF-16BE -t UTF-8 2>/dev/null || echo "$title")
    
    echo "pdf path : $pdf_file" >> ./menu.pdf
    echo "pdf title : $title" >> ./menu.pdf
    echo "-----------------------------------------" >> ./menu.pdf
done 